﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Food : MonoBehaviour
{
    private List<MyPoint> _foodsPoint = new List<MyPoint>();
    public List<MyPoint> foodsPoint {
        set {
            _foodsPoint = value;
        }
        get {
            // if (_foodsPoint.Count == 0) {

            // }
            return _foodsPoint;
        }
    }
    public List<MyPoint> creatFoods(List<MyPoint> snakePoint, int num) {
        while (true)
        {
            if (foodsPoint.Count != 0) return foodsPoint; 
            // List<MyPoint> foodsPoint = new List<MyPoint>();
            for (int i = 0; i < num; i++) {
                MyPoint point = new MyPoint(Random.Range(0, PublicData.kSreenSize), Random.Range(0, PublicData.kSreenSize));
                if (snakePoint.Contains(point) || foodsPoint.Contains(point)) {
                    i--;
                } else if (foodsPoint.Count + snakePoint.Count == PublicData.kSreenSize * PublicData.kSreenSize) {
                    return foodsPoint;
                } else {
                    foodsPoint.Add(point);
                }
            }
            // _foodsPoint = foodsPoint;
            return foodsPoint;
        }
        
    }
}
